package PageOR;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.ui.Select;

public class FindAFlight 
{
	WebDriver driver;
	
	@FindBy(how = How.XPATH, using = "//input[@value='oneway' and @name='tripType']")
	public WebElement rdb_TripType_OneWay;
	
	@FindBy(how = How.XPATH, using = "//input[@value='roundtrip' and @name='tripType']")
	public WebElement rdb_TripType_RoundTrip;
	
	@FindBy(how = How.NAME, using = "passCount")
	public WebElement lst_PassengerCount;
	
	@FindBy(how = How.NAME, using = "fromPort")
	public WebElement lst_FromPort;
	
	@FindBy(how = How.NAME, using = "fromMonth")
	public WebElement lst_FromMonth;
	
	@FindBy(how = How.NAME, using = "fromDay")
	public WebElement lst_FromDay;
	
	@FindBy(how = How.NAME, using = "toPort")
	public WebElement lst_ToPort;
	
	@FindBy(how = How.NAME, using = "toMonth")
	public WebElement lst_ToMonth;
	
	@FindBy(how = How.NAME, using = "toDay")
	public WebElement lst_ToDay;
	
	@FindBy(how = How.XPATH, using = "//input[@value='Coach' and @name='servClass']")
	public WebElement rdb_EconomyClass;
	
	@FindBy(how = How.XPATH, using = "//input[@value='Business' and @name='servClass']")
	public WebElement rdb_BusinessClass;
	
	@FindBy(how = How.XPATH, using = "//input[@value='First' and @name='servClass']")
	public WebElement rdb_FirstClass;
	
	@FindBy(how = How.NAME, using = "airline")
	public WebElement lst_Airline;
	
	@FindBy(how = How.XPATH, using = "//input[@name='findFlights' and @type='image']")
	public WebElement btn_Continue;
	
	public FindAFlight(WebDriver driver)
	{
		this.driver=driver;
	}
	
	public boolean func_EnterFlightDEtails(String strTripType,int intPassengerCount,String strFromPort,String strFromMonth,int intFromDay,
			String ToPort,String strToMonth,int intToDay,String strClass,String strAirline)
	{
		if (strTripType.equalsIgnoreCase("Round Trip"))
		{
			rdb_TripType_RoundTrip.click();
		}else
		{
			rdb_TripType_OneWay.click();
		}
		new Select(lst_PassengerCount).selectByValue(String.valueOf(intPassengerCount));
		new Select(lst_FromPort).selectByValue(String.valueOf(strFromPort));
		new Select(lst_FromMonth).selectByVisibleText(strFromMonth);
		new Select(lst_FromDay).selectByValue(String.valueOf(intFromDay));
		new Select(lst_ToPort).selectByValue(String.valueOf(ToPort));
		new Select(lst_ToMonth).selectByVisibleText(strToMonth);
		new Select(lst_ToDay).selectByValue(String.valueOf(intToDay));
		
		if (strClass.equalsIgnoreCase("First class"))
		{
			rdb_FirstClass.click();
		}else if (strClass.equalsIgnoreCase("Business class"))
		{
			rdb_BusinessClass.click();
		}
		else
		{
			rdb_EconomyClass.click();
		}
		new Select(lst_Airline).selectByVisibleText(strAirline);			
		btn_Continue.submit();
		return false;	
	}
}
